#!/usr/bin/env bash

# mlaine@sdfeu

source '../say.sh'
cd '../faqfiles'

nick="$1"
chan="$2"
args=("${@:3}")
faq="${args[0]}"

if [[ "${#args[@]}" -ge 2 && "${args[-2]}" = '>' &&
    ! "${args[-1]}" =~ '#' ]]; then
    chan="${args[-1]}"
fi

if [[ -f "$faq" ]]; then
    readarray -t msg < "$faq"
else
    faqs=(*)
    msg="Available topics: ${faqs[*]}"
fi

say "$chan" "${msg[@]}"

